{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "### supermind数据 机器学习训练v3()\n",
    "    特征：+行业涨停率 \n",
    "    首次涨停模型：v5_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import time,datetime\n",
    "from datetime import date\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import log_loss\n",
    "import lightgbm as lgb\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score\n",
    "execfile('v4/v4_util.py')\n",
    "execfile('v4/train_util.py')\n",
    "\n",
    "\n",
    "# 获取当前日期\n",
    "today_str = date.today().strftime(\"%m_%d\")\n",
    "out_path = 'output/'\n",
    "print(today_str)\n",
    "lgb.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df = pd.read_csv('output/v4_train.csv')\n",
    "train_df = train_df[(train_df['date'] > '2017-01-01')]\n",
    "p_col(train_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# execfile('v4/analysis.py')\n",
    "# analyze_nan_columns(train_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# list(train_df.columns)\n",
    "# train_df[['date','code','turnover']]\n",
    "# p_col(train_df)\n",
    "# train_df = train_df.dropna()\n",
    "# print(len(train_df))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# train_df.sort_values(by=['ret5'])[-10:]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "### 一、10cm个股首次涨停训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "execfile('v4/label.py')\n",
    "execfile('v4/train10.py')\n",
    "f_zt_1_df = filter_10cm_zt_1(train_df)\n",
    "analyze_label_distribution(f_zt_1_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "execfile('v4/train10.py')\n",
    "train_10_recall_zt_1(f_zt_1_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "execfile('v4/train10.py')\n",
    "train_10_precision_zt_1(f_zt_1_df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "#### 二、首次出现涨幅大于4%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12",
   "metadata": {},
   "outputs": [],
   "source": [
    "execfile('v4/label.py')\n",
    "execfile('v4/train10.py')\n",
    "f_gt4_df = filter_10cm_gt4(train_df)\n",
    "analyze_label_distribution(f_gt4_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14",
   "metadata": {},
   "outputs": [],
   "source": [
    "execfile('v4/train10.py')\n",
    "train_recall_zt_after(f_gt4_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [],
   "source": [
    "   \n",
    "execfile('v4/train10.py')\n",
    "train_precision_zt_after(f_gt4_df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17",
   "metadata": {},
   "outputs": [],
   "source": [
    "# execfile('v4/label.py')\n",
    "# execfile('v4/train10.py')\n",
    "# f_outliner_df = filter_10cm_outlier(train_df)\n",
    "# analyze_label_distribution(f_outliner_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18",
   "metadata": {},
   "outputs": [],
   "source": [
    "# execfile('v4/train10.py')\n",
    "# # 训练模型系统\n",
    "# model_system = train_anomaly_detection_for_class3(f_outliner_df, target_class=3)\n",
    "\n",
    "# # # 预测新数据\n",
    "# # new_data = ... # 新数据\n",
    "# # predictions = model_system['combined_predict'](new_data)\n",
    "\n",
    "# # # 获取类别3的预测结果\n",
    "# # class3_predictions = (predictions == 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
